package com.guava.string;

import com.google.common.base.Strings;

/**
 * StringsTester--GuavaTest
 *
 * @author: Jovi
 * @createTime: 2018-05-10 17:14
 **/
public class StringsTester {

    public static void main(String[] args) {
        String a = "123456";

        /* minLength为补充到的最小长度，如果小于a.length的话不做处理 */
        System.out.println("补充结尾：" + Strings.padEnd(a, 10, 'x'));
        System.out.println("补充开头：" + Strings.padStart(a, 7, 'x'));

        String nulla = null;
        String emptya = "";
        System.out.println("判断 null 和 \"\" 是否为空：" + Strings.isNullOrEmpty(nulla) + "+" + Strings.isNullOrEmpty(emptya));

        System.out.println("将 \"\"转换为null：" + Strings.emptyToNull(emptya) + " 将 null转换为 \"\" " + Strings.nullToEmpty(nulla));

        System.out.println("重复字符串a：" + Strings.repeat(a, 3));

        String x = "你好，中国a";
        String y = "你好，上海a";
        System.out.println("提取相同前缀" + Strings.commonPrefix(x, y));
        System.out.println("提取相同后缀" + Strings.commonSuffix(x, y));

    }
}
